<template>
  <div>
    <h1>鉴定报表</h1>
    <el-alert
      v-if="upd_success===1"
      title="更新成功"
      type="success">
    </el-alert>
    <el-table
      :data="info1"
      height="360"
      border
      style="width: 100%">
      <el-table-column
        prop="bid"
        label="报表编号"
        align="center"
        width="95"
        :resizable="false">
      </el-table-column>
      <el-table-column
        prop="wid"
        label="物证编号"
        align="center"
        width="95"
        :resizable="false">
      </el-table-column>
      <el-table-column
        prop="submitdate"
        label="提交时间"
        align="center"
        width="160"
        :resizable="false">
      </el-table-column>
      <el-table-column
        prop="uid"
        label="提交者编号"
        align="center"
        width="140"
        :resizable="false">
      </el-table-column>
      <el-table-column
        prop="qid"
        label="待鉴定项目编号"
        align="center"
        width="150"
        :resizable="false">
      </el-table-column>
      <el-table-column
        prop="state"
        label="报表状态"
        align="center"
        width="135"
        :resizable="false">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="210"
        :resizable="false">
        <template slot-scope="scope">
          <el-dropdown @command="(command)=>{handleCommand(command, scope.row.bid)}">
            <span class="el-dropdown-link" >更新状态<i class="el-icon-arrow-down el-icon--right"></i></span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a">已受理</el-dropdown-item>
              <el-dropdown-item command="b">鉴定中</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "IdentifyList" ,
  data(){
    return {
      id: '',
      radio1: '报表编号',
      userinfo: '',
      del_success:'',
      upd_success:'',
      info1:[],
      info:{
        wid:'1'
      }
    }
  },
  beforeRouteEnter: (to, from, next) => {
    console.log('进入路由之前');//加载数据
    next(vm => {
      vm.selectinfo();
    })
  },
  beforeRouteLeave: (to, from, next) => {
    console.log('进入路由之后');
    next()
  },
  methods:{
    handleCommand(command,data) {
      this.upd_success='';
      if(command==="a"){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyUserController/setIdentifyState",
          params:{
            token:localStorage.getItem("token_only"),
            bid:data,
            state:"已受理"
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='300'){
            this.upd_success=1;
            this.selectinfo();
          }
          else if(res["data"]["code"]==='301'){
            this.$alert('系统错误', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='311'){
            this.$alert('请按流程更新状态', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
      else if(command==="b"){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyUserController/setIdentifyState",
          params:{
            token:localStorage.getItem("token_only"),
            bid:data,
            state:"鉴定中"
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='300'){
            this.upd_success=1;
            this.selectinfo();
          }
          else if(res["data"]["code"]==='301'){
            this.$alert('系统错误', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='311'){
            this.$alert('请按流程更新状态', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
    },
    selectinfo:function (){
      this.userinfo='';
      this.axios({
        method:"post",
        headers: { 'content-type': 'application/json' },
        url: "http://evidence.frogking.cn/identifyUserController/selectIdentifyFromJid",
        params:{
          token:localStorage.getItem("token_only"),
        }
      }).then(res=>{
        console.log(res)
        if(res["data"]["code"]==='306'){
          this.info1=res["data"]["item"];
        }
        else if(res["data"]["code"]==='307') {
          this.$alert('该报表不存在', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.userinfo = "";
            }
          });
        }
        else if(res["data"]["code"]==='310'){
          this.$alert('用户异常不存在', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.userinfo="";
            }
          });
        }
        else if(res["data"]["code"]==='000'){
          this.$alert('token失效', '错误提示', {
            confirmButtonText: '确定',
            callback: action => {
              this.$router.push("/login");
              localStorage.removeItem("token_only");
            }
          });
        }
        else if(res["data"]["code"]==='001'){
          this.$alert('身份不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
        else if(res["data"]["code"]==='002'){
          this.$alert('权限不满足，禁止操作', '错误提示', {
            confirmButtonText: '确定'
          });
        }
      }).catch(function (error) {
        console.log(error);
      });
    },
    select:function (){
      if(this.radio1==='报表编号'){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyAdmController/selectIdentifyByBid",
          params:{
            token:localStorage.getItem("token_only"),
            bid:this.userinfo
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='306'){
            this.info1=[res["data"]["item"]];
            this.info1["submitdate"];
          }
          else if(res["data"]["code"]==='307'){
            this.$alert('该报表不存在', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.userinfo="";
              }
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
      else if(this.radio1==='物证编号'){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyAdmController/selectIdentifyByWid",
          params:{
            token:localStorage.getItem("token_only"),
            wid:this.userinfo
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='306'){
            this.info1=res["data"]["item"];
            console.log(this.info1)
          }
          else if(res["data"]["code"]==='307'){
            this.$alert('该报表不存在', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.userinfo="";
              }
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
      else if(this.radio1==='提交者编号'){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyAdmController/selectIdentifyByUid",
          params:{
            token:localStorage.getItem("token_only"),
            uid:this.userinfo
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='306'){
            this.info1=res["data"]["item"];
            console.log(this.info)
          }
          else if(res["data"]["code"]==='307'){
            this.$alert('该报表不存在', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.userinfo="";
              }
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
      else if(this.radio1==='鉴定机构编号'){
        this.axios({
          method:"post",
          headers: { 'content-type': 'application/json' },
          url: "http://evidence.frogking.cn/identifyAdmController/selectIdentifyByJid",
          params:{
            token:localStorage.getItem("token_only"),
            jid:this.userinfo
          }
        }).then(res=>{
          console.log(res)
          if(res["data"]["code"]==='306'){
            this.info1=res["data"]["item"];
            console.log(this.info)
          }
          else if(res["data"]["code"]==='307'){
            this.$alert('该报表不存在', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.userinfo="";
              }
            });
          }
          else if(res["data"]["code"]==='000'){
            this.$alert('token失效', '错误提示', {
              confirmButtonText: '确定',
              callback: action => {
                this.$router.push("/login");
                localStorage.removeItem("token_only");
              }
            });
          }
          else if(res["data"]["code"]==='001'){
            this.$alert('身份不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
          else if(res["data"]["code"]==='002'){
            this.$alert('权限不满足，禁止操作', '错误提示', {
              confirmButtonText: '确定'
            });
          }
        }).catch(function (error) {
          console.log(error);
        });
      }
    },
  }
}
</script>

<style scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>
